package pers.qianyu.month_202012.date_20201226;

import pers.qianyu.util.model.*;

/**
 * 101. 对称二叉树
 * https://leetcode-cn.com/problems/symmetric-tree/
 *
 * @author mizzle rain
 * @date 2020-12-26 22:55
 */
public class IsSymmetric {
    public boolean isSymmetric(TreeNode root) {
        if (root == null) return true;
        return recur(root.left, root.right);
    }

    private boolean recur(TreeNode leftNode, TreeNode rightNode) {
        if (leftNode == null && rightNode == null) {
            return true;
        } else if (leftNode == null || rightNode == null) {
            return false;
        } else {
            return leftNode.val == rightNode.val
                    && recur(leftNode.right, rightNode.left)
                    && recur(leftNode.left, rightNode.right);
        }
    }
}
